﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows.Forms;

namespace com.orange.examination
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["admin"] == null)
            {
                Response.Redirect("../LoginAndRegister/Login.aspx");
            }
            if (!IsPostBack)
            {
                string sql = "select LessonName  from tb_Lesson";
                DataSet ds = BaseClass.ExecDataSet(sql);
                ddlkm.DataSource = ds.Tables[0];
                ddlkm.DataTextField = "LessonName";
                ddlkm.DataBind();
            }
        }

        protected void btnconfirm_Click(object sender, EventArgs e)
        {
            if (txtsubject.Text == "" || txtAnsA.Text == "" || txtAnsB.Text == "" ||
                txtAnsC.Text == "" || txtAnsD.Text == "")
            {
                Response.Write("<script type=text/javascript>alert('请将信息输入完整！')</script>");
                return;
            }
            else
            {
                string isfb = "";
                if (cbFB.Checked == true)
                    isfb = "1";
                else
                    isfb = "0";

                string str = "insert into tb_test(testContent,testAns1,testAns2,testAns3,testAns4,rightAns,pub,testCourse) values('" + txtsubject.Text.Trim() + "','" + txtAnsA.Text.Trim() + "','" + txtAnsB.Text.Trim() + "','" + txtAnsC.Text.Trim() + "','" + txtAnsD.Text.Trim() + "','" + rblRightAns.SelectedValue.ToString() + "','" + isfb + "','" + ddlkm.SelectedItem.Text + "')";
                BaseClass.OperateData(str);
                Response.Write("<script type=text/javascript>alert('试题信息添加成功！')</script>");
                btnconcel_Click(sender, e);
            }

        }


        protected void btnconcel_Click(object sender, EventArgs e)
        {
            txtsubject.Text = "";
            txtAnsA.Text = "";
            txtAnsB.Text = "";
            txtAnsC.Text = "";
            txtAnsD.Text = "";
        }

    }
    }
